#include <bits/stdc++.h>
#define int long long
using namespace std;

class Matrix {
public:
    int n, a[101][101];
    Matrix(int N)
    {
        n = N;
        memset(a, 0, sizeof a);
    }
    Matrix operator*(Matrix& b)
    {
        Matrix c(n);
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                for (int k = 1; k <= n; k++)
                    c.a[i][j] += a[i][k] * b.a[k][j], c.a[i][j] %= 1000000007;
        return c;
    }
};

Matrix quick_pow(Matrix a, int k)
{
    Matrix ans(a.n);
    for (int i = 1; i <= a.n; i++)
        ans.a[i][i] = 1;
    while (k) {
        if (k & 1)
            ans = ans * a;
        a = a * a;
        k >>= 1;
    }
    return ans;
}

signed main()
{
    int n, k;
    cin >> n >> k;
    Matrix a(n);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            cin >> a.a[i][j];
    Matrix b = quick_pow(a, k);

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            cout << b.a[i][j] << " \n"[j == n];
    return 0;
}